package study.chapter03.thread.operation;

//线程强制执行
public class TestThread4 {
    public static void main(String[] args) {
        Thread mainThread = Thread.currentThread();

        //子线程
        new Thread(() -> {
            for (int i = 0; i < 10; i++) {
                if (i == 5){
                    try {
                        System.out.println("主线程加入进来了，让主线程执行完所有代码，再执行子线程的代码！！");
                        mainThread.join();
                        System.out.println("主线程执行完了，子线程继续执行子线程里面的代码");
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("A线程：" + i);
                try {
                    Thread.sleep(500);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        }).start();



        //主线程
        for (int i = 0; i < 10; i++) {
            System.out.println("主线程：" + i);
            try {
                Thread.sleep(500);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
        }


    }
}

